from django.http import HttpResponse
from django.shortcuts import render, redirect, reverse
from django.views.generic import View
from .froms import MessageBoardForm


def index(request):
    return HttpResponse('index')

class IndexView(View):
    def get(self,request):
        form = MessageBoardForm()
        return render(request,'front7/index.html',context={'form':form})

    def post(self,request):
        form = MessageBoardForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data.get('title')
            content = form.cleaned_data.get('content')
            email = form.cleaned_data.get('email')
            reply = form.cleaned_data.get('reply')
            print(
                {'title':title,'content':content,'email':email,'reply':reply}
            )
            return HttpResponse('success')
        else:
            print(form.errors)
            return HttpResponse('fails')